<?php
namespace app\common\model;

use think\Db;

class PushChannelPushLog extends Base
{
    protected $table = 'push_channel_push_logs';

    protected static function init()
    {

    }

    public function getCreateTimeLabelAttr($value, $data)
    {
        if (empty($data['create_time'])) {

            return '';
        }

        return date('Y-m-d H:i:s', $data['create_time']);
    }

    public function getStatusTimeLabelAttr($value, $data)
    {
        if (empty($data['status_time'])) {

            return '';
        }

        return date('Y-m-d H:i:s', $data['status_time']);
    }

  

    public function getTypeLabelAttr($value, $data)
    {
        if ($data['type'] == 1) {
           return '独享';
        }

        if ($data['type'] == 2) {
            return '共享';
        }

        return '未知';
    }
    
    public function getPushChannelIdLabelAttr($value, $data)
    {
        $push_channel = PushChannel::get(array('id' => $data['push_channel_id']));
        
        if (empty($push_channel)) {
            return '';
        }
        
        return $push_channel['name'];
    }

    public function getPushChannelIdsLabelAttr($value, $data)
    {
        // $push_channel = PushChannel::get(array('id' => $data['push_channel_id']));
        $push_channel = Db::name('platforms')->where('id',$data['push_channel_id'])->find();
        if (empty($push_channel)) {
            return '';
        }
        
        return $push_channel['name'];
    }


    public function getStatusArrAttr($value, $data)
    {
        switch ($data['status']) {
            case 1:
                $result['status_label'] = '已获取';
                $result['status_class'] = 'layui-btn-default';
                break;
            case -1:
                $result['status_label'] = '已退回';
                $result['status_class'] = 'layui-btn-danger';
                break;
            default:
                $result['status_label'] = '未获取';
                $result['status_class'] = 'layui-btn-primary';
                break;
        }

        return $result;
    }
   



}